<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2021/5/26
 * Time: 10:23
 */

namespace app\admin\controller;


use think\Db;
use think\Request;

class Classes extends Base
{
    /**
     * 课程列表
     * @return mixed|\think\response\Json
     */
    public function index(){
        if(Request::instance()->isAjax()){
            $class_title = trim(input('class_title'), ' '); // 标题
            $class_cate_id = input('class_cate_id'); // 分类
            $class_type = input('class_type'); // 类型
            $class_is_recommend = input('class_is_recommend'); // 推荐
            $class_is_hot = input('class_is_hot'); // 热门
            $class_video_audio = input('class_video_audio'); // 课程形式
            $class_status = input('class_status'); // 状态
            
            $where['class_status'] = ['<>', 3];
            // 标题
            if(isset($class_title) && $class_title != ''){
                $where['class_title'] = ['like', '%' . $class_title . '%'];
            }
            // 分类
            if(isset($class_cate_id) && $class_cate_id != ''){
                $where['class_cate_id'] = $class_cate_id;
            }
            // 类型
            if(isset($class_type) && $class_type != ''){
                $where['class_type'] = $class_type;
            }
            // 是否推荐
            if(isset($class_is_recommend) && $class_is_recommend != ''){
                $where['class_is_recommend'] = $class_is_recommend;
            }
            // 是否热门
            if(isset($class_is_hot) && $class_is_hot != ''){
                $where['class_is_hot'] = $class_is_hot;
            }
            // 课程形式
            if(isset($class_video_audio) && $class_video_audio != ''){
                $where['class_video_audio'] = $class_video_audio;
            }
            // 状态
            if(isset($class_status) && $class_status != ''){
                $where['class_status'] = $class_status;
            }
    
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::table('up_class')
                ->join('up_class_cate', 'c_cate_id = class_cate_id', 'LEFT')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::table('up_class')
                ->join('up_class_cate', 'c_cate_id = class_cate_id', 'LEFT')
                ->field('class_id, class_title, c_cate_name, class_type, class_is_recommend, class_is_hot, 
                class_video_audio, class_status, class_price, class_section_number, class_apply_number, 
                class_thumb, class_update_time, class_create_time')
                ->where($where)
                ->page($Nowpage, $limits)
                ->order('class_create_time desc')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $cate = Db::table('up_class_cate')->where('c_cate_status', 1)->field('c_cate_id, c_cate_name')->select();
        $this->assign([
            'cate' => $cate
        ]);
        return $this->fetch();
    }
    
    /**
     * 新增课程
     * @return mixed|\think\response\Json
     */
    public function classAdd(){
        if(Request::instance()->isPost()){
            $class_title = trim(input('class_title'));
            $class_cate_id = input('class_cate_id');
            $class_type = input('class_type');
            $class_user_rule = input('class_user_rule/a');
            $class_user_rule = implode(',', $class_user_rule);
            $class_is_recommend = input('class_is_recommend');
            $class_is_hot = input('class_is_hot');
            $class_video_audio = input('class_video_audio');
            $class_status = input('class_status');
            $class_price = input('class_price');
            $class_thumb = input('class_thumb');
            $class_images = input('class_images');
            $class_intro = input('class_intro');
            $class_shiyong_user = input('class_shiyong_user');
            $class_teacher_name = input('class_teacher_name');
            $class_teacher_image = input('class_teacher_image');
            $class_teacher_intro = input('class_teacher_intro');
            $class_is_forever = input('class_is_forever');
            $class_valid_date = input('class_valid_date');
            
            if($class_type == 2 && $class_price == 0){
                return json(['code' => 100, 'msg' => '请设置正确的课程价格']);
            }
            if($class_is_forever == 1 && $class_valid_date == 0){
                return json(['code' => 100, 'msg' => '请设置正确的时效天数']);
            }
            
            $class = [
                'class_title' => $class_title,
                'class_cate_id' => $class_cate_id,
                'class_type' => $class_type,
                'class_user_rule' => $class_user_rule,
                'class_is_recommend' => $class_is_recommend,
                'class_is_hot' => $class_is_hot,
                'class_video_audio' => $class_video_audio,
                'class_status' => $class_status,
                'class_price' => $class_price,
                'class_thumb' => $class_thumb,
                'class_images' => $class_images,
                'class_intro' => $class_intro,
                'class_shiyong_user' => $class_shiyong_user,
                'class_teacher_name' => $class_teacher_name,
                'class_teacher_image' => $class_teacher_image,
                'class_teacher_intro' => $class_teacher_intro,
                'class_is_forever' => $class_is_forever,
                'class_valid_date' => $class_valid_date,
                'class_create_time' => date('Y-m-d H:i:s')
            ];
            $res = Db::table('up_class')->insert($class);
            if($res){
                return json(['code' => 200, 'msg' => '添加成功']);
            }else{
                return json(['code' => 100, 'msg' => '添加失败']);
            }
        }
        $cate = Db::table('up_class_cate')->where('c_cate_status', 1)->field('c_cate_id, c_cate_name')->select();
        $this->assign([
            'cate' => $cate
        ]);
        return $this->fetch();
    }
    
    /**
     * 课程详情
     * @return mixed
     */
    public function classDetail(){
        $class_id = input('class_id');
        $class = Db::table('up_class')
            ->join('up_class_cate', 'c_cate_id = class_cate_id', 'LEFT')
            ->where('class_id', $class_id)
            ->field('class_title, c_cate_name, class_type, class_user_rule, class_is_recommend, class_is_hot, 
            class_video_audio, class_status, class_price, class_section_number, class_apply_number, 
            class_thumb, class_images, class_intro, class_shiyong_user, class_teacher_name, class_teacher_image, 
            class_teacher_intro, class_is_forever, class_valid_date, class_create_time')
            ->find();
        // 观看权限
        $user_rule = [1 => '普通用户', 2 => '特惠商品', 3 => '脖脸皮'];
        $rule_arr = [];
        $class_user_rule = explode(',', $class['class_user_rule']);
        foreach($class_user_rule as $k => $v){
            $rule_arr[$k] = $user_rule[$v];
        }
        $class['class_user_rule'] = implode(',', $rule_arr);
        // 图集
        if($class['class_images']){
            $class['class_images'] = explode(',', $class['class_images']);
        }else{
            $class['class_images'] = [];
        }
        $this->assign('class', $class);
        return $this->fetch();
    }
    
    /**
     * 编辑课程
     * @return mixed|\think\response\Json
     */
    public function classEdit(){
        $class_id = input('class_id');
        if(Request::instance()->isPost()){
            $class_title = trim(input('class_title'));
            $class_cate_id = input('class_cate_id');
            $class_type = input('class_type');
            $class_user_rule = input('class_user_rule/a');
            $class_user_rule = implode(',', $class_user_rule);
            $class_is_recommend = input('class_is_recommend');
            $class_is_hot = input('class_is_hot');
            $class_video_audio = input('class_video_audio');
            $class_status = input('class_status');
            $class_price = input('class_price');
            $class_thumb = input('class_thumb');
            $class_images = input('class_images');
            $class_intro = input('class_intro');
            $class_shiyong_user = input('class_shiyong_user');
            $class_teacher_name = input('class_teacher_name');
            $class_teacher_image = input('class_teacher_image');
            $class_teacher_intro = input('class_teacher_intro');
            $class_is_forever = input('class_is_forever');
            $class_valid_date = input('class_valid_date');
    
            if($class_type == 2 && $class_price == 0){
                return json(['code' => 100, 'msg' => '请设置正确的课程价格']);
            }
            if($class_is_forever == 1 && $class_valid_date == 0){
                return json(['code' => 100, 'msg' => '请设置正确的时效天数']);
            }
            
            $class = [
                'class_title' => $class_title,
                'class_cate_id' => $class_cate_id,
                'class_type' => $class_type,
                'class_user_rule' => $class_user_rule,
                'class_is_recommend' => $class_is_recommend,
                'class_is_hot' => $class_is_hot,
                'class_video_audio' => $class_video_audio,
                'class_status' => $class_status,
                'class_price' => $class_price,
                'class_thumb' => $class_thumb,
                'class_images' => $class_images,
                'class_intro' => $class_intro,
                'class_shiyong_user' => $class_shiyong_user,
                'class_teacher_name' => $class_teacher_name,
                'class_teacher_image' => $class_teacher_image,
                'class_teacher_intro' => $class_teacher_intro,
                'class_is_forever' => $class_is_forever,
                'class_valid_date' => $class_valid_date,
                'class_update_time' => date('Y-m-d H:i:s')
            ];
            $res = Db::table('up_class')->where('class_id', $class_id)->update($class);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $cate = Db::table('up_class_cate')->where('c_cate_status', 1)->field('c_cate_id, c_cate_name')->select();
        $class = Db::table('up_class')
            ->where('class_id', $class_id)
            ->field('class_title, class_cate_id, class_type, class_user_rule, class_is_recommend, 
            class_is_hot, class_video_audio, class_status, class_price, class_thumb, class_images, 
            class_intro, class_shiyong_user, class_teacher_name, class_teacher_image, class_teacher_intro, 
            class_is_forever, class_valid_date')
            ->find();
        $this->assign([
            'cate' => $cate,
            'class_id' => $class_id,
            'class' => $class
        ]);
        return $this->fetch();
    }
    
    /**
     * 下架
     * @return \think\response\Json
     */
    public function classDown(){
        $class_id = input('id');
        $res = Db::table('up_class')->update(['class_status' => 2, 'class_id' => $class_id]);
        if($res){
            return json(['code' => 200, 'msg' => '操作成功']);
        }else{
            return json(['code' => 100, 'msg' => '操作失败']);
        }
    }
    
    /**
     * 上架
     * @return \think\response\Json
     */
    public function classOn(){
        $class_id = input('id');
        $res = Db::table('up_class')->update(['class_status' => 1, 'class_id' => $class_id]);
        if($res){
            return json(['code' => 200, 'msg' => '操作成功']);
        }else{
            return json(['code' => 100, 'msg' => '操作失败']);
        }
    }
    
    /**
     * 取消推荐
     * @return \think\response\Json
     */
    public function classUnrecommend(){
        $class_id = input('id');
        $res = Db::table('up_class')->update(['class_is_recommend' => 2, 'class_id' => $class_id]);
        if($res){
            return json(['code' => 200, 'msg' => '操作成功']);
        }else{
            return json(['code' => 100, 'msg' => '操作失败']);
        }
    }
    
    /**
     * 推荐
     * @return \think\response\Json
     */
    public function classRecommend(){
        $class_id = input('id');
        $res = Db::table('up_class')->update(['class_is_recommend' => 1, 'class_id' => $class_id]);
        if($res){
            return json(['code' => 200, 'msg' => '操作成功']);
        }else{
            return json(['code' => 100, 'msg' => '操作失败']);
        }
    }
    
    /**
     * 取消热门
     * @return \think\response\Json
     */
    public function classUnhot(){
        $class_id = input('id');
        $res = Db::table('up_class')->update(['class_is_hot' => 2, 'class_id' => $class_id]);
        if($res){
            return json(['code' => 200, 'msg' => '操作成功']);
        }else{
            return json(['code' => 100, 'msg' => '操作失败']);
        }
    }
    
    /**
     * 设置热门
     * @return \think\response\Json
     */
    public function classHot(){
        $class_id = input('id');
        $res = Db::table('up_class')->update(['class_is_hot' => 1, 'class_id' => $class_id]);
        if($res){
            return json(['code' => 200, 'msg' => '操作成功']);
        }else{
            return json(['code' => 100, 'msg' => '操作失败']);
        }
    }
    
    /**
     * 删除课程
     * @return \think\response\Json
     */
    public function classDel(){
        $class_id = input('id');
        $res = Db::table('up_class')->update(['class_status' => 3, 'class_id' => $class_id]);
        if($res){
            return json(['code' => 200, 'msg' => '删除成功']);
        }else{
            return json(['code' => 100, 'msg' => '删除失败']);
        }
    }
    
    /**
     * 章节列表
     * @return \think\response\Json
     */
    public function classSection(){
        if(Request::instance()->isAjax()){
            $where = [
                'c_section_status' => ['<>', 3],
                'c_section_class_id' => session('class_id')
            ];
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::table('up_class_section')->where($where)->count();// 获取总条数
            $lists = Db::table('up_class_section')
                ->field('c_section_id, c_section_name, c_section_sort, c_section_time, 
                c_section_status, c_section_update_time')
                ->where($where)
                ->page($Nowpage, $limits)
                ->order('c_section_sort asc')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $class_id = input('class_id');
        if(isset($class_id) && $class_id != '') session('class_id', $class_id);
        return $this->fetch();
    }
    
    /**
     * 添加章节
     * @return mixed|\think\response\Json
     */
    public function sectionAdd(){
        $class = Db::table('up_class')->where('class_id', session('class_id'))->field('class_video_audio')->find();
        if(Request::instance()->isPost()){
            $c_section_name = trim(input('c_section_name'));
            $c_section_sort = input('c_section_sort');
            $c_section_status = input('c_section_status');
            $c_section_url = input('c_section_url');
            $c_section_detail = input('c_section_detail');
            
            $insert = [
                'c_section_class_id' => session('class_id'),
                'c_section_name' => $c_section_name,
                'c_section_sort' => $c_section_sort,
                'c_section_status' => $c_section_status,
                'c_section_detail' => $c_section_detail,
                'c_section_time' => date('Y-m-d H:i:s')
            ];
            
            if($c_section_url){
                if($class['class_video_audio'] == 1){ // 视频转码
                    //转码的文件url
                    $url = config('qiniu.domain') . $c_section_url;//未转码之前的视频url，用于获取视频信息
                    $video_info = file_get_contents($url . '?avinfo');
                    $video_info = json_decode($video_info,true);
                    // 时长
                    $time = explode('.', $video_info['streams'][0]['duration']);
                    $fen = floor($time[0]/60);
                    $miao = floor(($time[0]-$fen*60)%60);
                    $c_section_duration = $fen . ':' . $miao;
                    $insert['c_section_duration'] = $c_section_duration;
                    // 大小
//                    $video_size = $video_info['format']['size'];
//                    $insert['bt_size'] = $video_size;
                    // 转码
                    $this->zhuanma($c_section_url);
                    $insert['c_section_url'] = config('qiniu.domain') . 'video_' . $c_section_url;
                }else{ // 音频
                    $audio_info = file_get_contents($c_section_url . '?avinfo');
                    $audio_info = json_decode($audio_info,true);
                    // 时长
                    $time = explode('.', $audio_info['streams'][0]['duration']);
                    $fen = floor($time[0]/60);
                    $miao = floor(($time[0]-$fen*60)%60);
                    $c_section_duration = $fen . ':' . $miao;
                    $insert['c_section_duration'] = $c_section_duration;
                    $insert['c_section_url'] = $c_section_url;
                }
            }
            Db::startTrans();
            try{
                // 插入章节
                Db::table('up_class_section')->insert($insert);
                // 课程章节数+1
                Db::table('up_class')->where('class_id', session('class_id'))->setInc('class_section_number');
                Db::commit();
                return json(['code' => 200, 'msg' => '添加成功']);
            }catch(\Exception $e){
                Db::rollback();
                return json(['code' => 100, 'msg' => $e->getMessage()]);
            }
        }
        if($class['class_video_audio'] == 1){
            return $this->fetch('classes/section_add_video');
        }else{
            return $this->fetch('classes/section_add_audio');
        }
    }
    
    /**
     * 章节详情
     * @return mixed
     */
    public function sectionDetail(){
        $c_section_id = input('c_section_id');
        $section = Db::table('up_class_section')
            ->where('c_section_id', $c_section_id)
            ->field('c_section_class_id, c_section_name, c_section_sort, c_section_url, c_section_time, c_section_detail')
            ->find();
        $class_video_audio = Db::table('up_class')->where('class_id', $section['c_section_class_id'])->value('class_video_audio');
        $this->assign([
            'section' => $section,
            'class_video_audio' => $class_video_audio
        ]);
        return $this->fetch();
    }
    
    /**
     * 编辑章节
     * @return mixed|\think\response\Json
     */
    public function sectionEdit(){
        $c_section_id = input('c_section_id');
        if(Request::instance()->isPost()){
            $c_section_name = trim(input('c_section_name'));
            $c_section_sort = input('c_section_sort');
            $c_section_status = input('c_section_status');
            $c_section_url = input('c_section_url');
            $class_video_audio = input('class_video_audio');
            $c_section_detail = input('c_section_detail');
    
            $update = [
                'c_section_name' => $c_section_name,
                'c_section_sort' => $c_section_sort,
                'c_section_status' => $c_section_status,
                'c_section_detail' => $c_section_detail,
                'c_section_update_time' => date('Y-m-d H:i:s')
            ];
            if($c_section_url){
                if($class_video_audio == 1){ // 视频转码
                    //转码的文件url
                    $url = config('qiniu.domain') . $c_section_url;//未转码之前的视频url，用于获取视频信息
                    $video_info = file_get_contents($url . '?avinfo');
                    $video_info = json_decode($video_info,true);
                    // 时长
                    $time = explode('.', $video_info['streams'][0]['duration']);
                    $fen = floor($time[0]/60);
                    $miao = floor(($time[0]-$fen*60)%60);
                    $c_section_duration = $fen . ':' . $miao;
                    $update['c_section_duration'] = $c_section_duration;
                    // 大小
//                    $video_size = $video_info['format']['size'];
//                    $insert['bt_size'] = $video_size;
                    // 转码
                    $this->zhuanma($c_section_url);
                    $update['c_section_url'] = config('qiniu.domain') . 'video_' . $c_section_url;
                }else{ // 音频
                    $audio_info = file_get_contents($c_section_url . '?avinfo');
                    $audio_info = json_decode($audio_info,true);
                    // 时长
                    $time = explode('.', $audio_info['streams'][0]['duration']);
                    $fen = floor($time[0]/60);
                    $miao = floor(($time[0]-$fen*60)%60);
                    $c_section_duration = $fen . ':' . $miao;
                    $update['c_section_duration'] = $c_section_duration;
                    $update['c_section_url'] = $c_section_url;
                }
            }else{
                return json(['code' => 100, 'msg' => '请上传音视频']);
            }
            $res = Db::table('up_class_section')->where('c_section_id', $c_section_id)->update($update);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
            
        }
        $section = Db::table('up_class_section')
            ->where('c_section_id', $c_section_id)
            ->field('c_section_status, c_section_name, c_section_sort, c_section_url, c_section_class_id, 
            c_section_detail')
            ->find();
        $class_video_audio = Db::table('up_class')->where('class_id', $section['c_section_class_id'])->value('class_video_audio');
        $this->assign([
            'c_section_id' => $c_section_id,
            'section' => $section,
            'class_video_audio' => $class_video_audio
        ]);
        if($class_video_audio == 1){
            return $this->fetch('classes/section_edit_video');
        }else{
            return $this->fetch('classes/section_edit_audio');
        }
    }
    
    /**
     * 下架
     * @return \think\response\Json
     */
    public function sectionDown(){
        $c_section_id = input('id');
        $res = Db::table('up_class_section')->update(['c_section_status' => 2, 'c_section_id' => $c_section_id]);
        if($res){
            return json(['code' => 200, 'msg' => '操作成功']);
        }else{
            return json(['code' => 100, 'msg' => '操作失败']);
        }
    }
    
    /**
     * 上架
     * @return \think\response\Json
     */
    public function sectionOn(){
        $c_section_id = input('id');
        $res = Db::table('up_class_section')->update(['c_section_status' => 1, 'c_section_id' => $c_section_id]);
        if($res){
            return json(['code' => 200, 'msg' => '操作成功']);
        }else{
            return json(['code' => 100, 'msg' => '操作失败']);
        }
    }
    
    /**
     * 删除
     * @return \think\response\Json
     */
    public function sectionDel(){
        $c_section_id = input('id');
        $class_id = Db::table('up_class_section')->where('c_section_id', $c_section_id)->value('c_section_class_id');
        Db::startTrans();
        try{
            Db::table('up_class_section')->update(['c_section_status' => 3, 'c_section_id' => $c_section_id]);
            Db::table('up_class')->where('class_id', $class_id)->setDec('class_section_number');
            Db::commit();
            return json(['code' => 200, 'msg' => '删除成功']);
        }catch(\Exception $e){
            Db::rollback();
            return json(['code' => 100, 'msg' => $e->getMessage()]);
        }
    }
    
    /**
     * 评价列表
     * @return mixed|\think\response\Json
     */
    public function classCommentList(){
        if(Request::instance()->isAjax()){
            $where = [
                'c_comment_status' => 1,
                'c_comment_class_id' => session('class_id')
            ];
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::table('up_class_comment')
                ->join('up_u_user', 'user_id = c_comment_user_id', 'LEFT')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::table('up_class_comment')
                ->join('up_u_user', 'user_id = c_comment_user_id', 'LEFT')
                ->field('c_comment_id, c_comment_content, c_comment_star, c_comment_time, user_username, 
                user_phone')
                ->where($where)
                ->page($Nowpage, $limits)
                ->order('c_comment_time desc')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $class_id = input('class_id');
        if(isset($class_id) && $class_id != '') session('class_id', $class_id);
        return $this->fetch();
    }
    
    /**
     * 回复评价
     * @return mixed|\think\response\Json
     */
    public function replyComment(){
        $c_comment_id = input('c_comment_id');
        if(Request::instance()->isPost()){
            $c_reply_content = input('c_reply_content');
            
            $reply = [
                'c_reply_type' => 1,
                'c_reply_user_id' => 0,
                'c_reply_admin_id' => session('uid'),
                'c_reply_comment_id' => $c_comment_id,
                'c_reply_class_id' => session('class_id'),
                'c_reply_reply_id' => 0,
                'c_reply_content' => $c_reply_content,
                'c_reply_from' => 2,
                'c_reply_time' => date('Y-m-d H:i:s')
            ];
            $res = Db::table('up_class_reply')->insert($reply);
            if($res){
                return json(['code' => 200, 'msg' => '回复成功']);
            }else{
                return json(['code' => 100, 'msg' => '回复失败']);
            }
        }
        $this->assign('c_comment_id', $c_comment_id);
        return $this->fetch();
    }
    
    /**
     * 回复列表
     * @return mixed|\think\response\Json
     */
    public function classReplyList(){
        if(Request::instance()->isAjax()){
            $where = [
                'c_reply_status' => 1,
                'c_reply_comment_id' => session('c_comment_id')
            ];
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::table('up_class_reply')
                ->join('up_u_user', 'user_id = c_reply_user_id', 'LEFT')
                ->join('up_admin', 'id = c_reply_admin_id', 'LEFT')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::table('up_class_reply')
                ->join('up_u_user', 'user_id = c_reply_user_id', 'LEFT')
                ->join('up_admin', 'id = c_reply_admin_id', 'LEFT')
                ->field('c_reply_id, c_reply_content, user_username, username, user_phone, phone, c_reply_from, 
                c_reply_time')
                ->where($where)
                ->page($Nowpage, $limits)
                ->order('c_reply_time desc')
                ->select();
            if($lists){
                foreach($lists as $k => $v){
                    // 发布者&手机号
                    if($v['c_reply_from'] == 1){
                        $lists[$k]['reply_user'] = $v['user_username'];
                        $lists[$k]['reply_phone'] = $v['user_phone'];
                    }else{
                        $lists[$k]['reply_user'] = $v['username'];
                        $lists[$k]['reply_phone'] = $v['phone'];
                    }
                }
            }
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $c_comment_id = input('c_comment_id');
        if(isset($c_comment_id) && $c_comment_id != '') session('c_comment_id', $c_comment_id);
        return $this->fetch();
    }
    
    /**
     * 回复回复
     * @return mixed|\think\response\Json
     */
    public function replyReply(){
        $c_reply_id = input('c_reply_id');
        if(Request::instance()->isPost()){
            $c_reply_content = input('c_reply_content');
            $comment = Db::table('up_class_comment')
                ->where('c_comment_id', session('c_comment_id'))
                ->field('c_comment_class_id')
                ->find();
    
            $reply = [
                'c_reply_type' => 2,
                'c_reply_user_id' => 0,
                'c_reply_admin_id' => session('uid'),
                'c_reply_comment_id' => session('c_comment_id'),
                'c_reply_class_id' => $comment['c_comment_class_id'],
                'c_reply_reply_id' => $c_reply_id,
                'c_reply_content' => $c_reply_content,
                'c_reply_from' => 2,
                'c_reply_time' => date('Y-m-d H:i:s')
            ];
            $res = Db::table('up_class_reply')->insert($reply);
            if($res){
                return json(['code' => 200, 'msg' => '回复成功']);
            }else{
                return json(['code' => 100, 'msg' => '回复失败']);
            }
        }
        $this->assign('c_reply_id', $c_reply_id);
        return $this->fetch();
    }
}